package com.nancy.java_design.memento.whitebox;

/**
 * 备忘录模式：在不破坏封装性的前提下，捕获一个对象的内部状态，并在该对象之外保存这个状态。这样以后就可将该对象恢复到原先保存的状态
 * 发起人角色
 */
public class MementoRole {
    private Integer vit;// 生命力
    private Integer def;//防御力
    private Integer power;//攻击力

    //初始化武力值
    public void initState() {
        this.vit = 100;
        this.def = 100;
        this.power = 100;
    }

    //声明备忘录管理者角色，保存角色状态
    public MementoManage saveStatue() {
        return new MementoManage(this.vit, this.def, this.power);
    }

    //战斗
    public void fight() {
        System.out.println("战斗中...");
        this.vit = 0;
        this.def = 0;
        this.power = 0;
    }

    //恢复状态
    public void recoverState(MementoManage mementoManage) {
        this.vit = mementoManage.getVit();
        this.def = mementoManage.getDef();
        this.power = mementoManage.getPower();
    }

    //展示状态
    public void showState() {
        System.out.println("生命力：" + this.vit);
        System.out.println("防御力:" + this.def);
        System.out.println("攻击力:" + this.power);
    }


    public MementoRole() {

    }

    public Integer getVit() {
        return vit;
    }

    public void setVit(Integer vit) {
        this.vit = vit;
    }

    public Integer getDef() {
        return def;
    }

    public void setDef(Integer def) {
        this.def = def;
    }

    public Integer getPower() {
        return power;
    }

    public void setPower(Integer power) {
        this.power = power;
    }
}
